﻿using System;
using Microsoft.Win32;
using System.Windows.Forms;

using Assc;

namespace Voize
{
    internal class CSettings
    {


        internal CSettings()
        {
            RegistryKey key = Registry.CurrentUser;
            if (key.OpenSubKey(@"Software\Voize", true) == null)
            {
                key = key.CreateSubKey(@"Software\Voize");
                m_Key = key;
                this.WriteDefaults();
            }
            else
                key = key.OpenSubKey(@"Software\Voize", true);

            m_Key = key;

            m_Config = new CConfig();
        }


        private RegistryKey m_Key;
        private CConfig m_Config;



        internal CConfig Configuration
        {
            get { return m_Config; }
        }


        private void WriteDefaults()
        {
            m_Key.SetValue("RememberWindowSizeAndLocation", "true");
            m_Key.SetValue("RememberLastSessionOnStartup", "false");
            m_Key.SetValue("MinimizeToSystemtrayOnClose", "false");
            m_Key.SetValue("AskPlaylistSavingOnClose", "true");
            m_Key.SetValue("IsScrobblingEnabled", "false");
            m_Key.SetValue("EnableServer", "false");
            m_Key.SetValue("ServerPort", "49159");
        }



        internal string AskPlaylistSavingOnClose
        {
            get
            {
                return
                 (string)m_Key.GetValue("AskPlaylistSavingOnClose");
            }
        }



        internal string RememberWindowSizeAndLocation
        {
            get { return 
                    (string)m_Key.GetValue("RememberWindowSizeAndLocation"); 
            }
        }



        internal string RememberLastSessionOnStartup
        {
            get { return 
                    (string)m_Key.GetValue("RememberLastSessionOnStartup"); 
            }
        }



        internal string MinimizeToSystemTrayOnClose
        {
            get { return 
                    (string)m_Key.GetValue("MinimizeToSystemtrayOnClose"); 
            }
        }



        internal string User
        {
            get
            {
                return
                    (string)m_Key.GetValue("User");
            }
        }


        internal string Password
        {
            get
            {
                return
                    (string)m_Key.GetValue("Password");
            }
        }



        internal string IsScrobblingEnabled
        {
            get { return (string)m_Key.GetValue("IsScrobblingEnabled"); }
        }


        internal string IsServerEnabled
        {
            get { return (string)m_Key.GetValue("EnableServer"); }
        }


        internal string ServerPort
        {
            get { return (string)m_Key.GetValue("ServerPort"); }
        }


        internal void WriteUserInfo(string user, string password)
        {
            m_Key.SetValue("User", user);
            m_Key.SetValue("Password", password);
        }


        internal void WriteServerInfo(bool enabled, string port)
        {
            if (enabled)
            {
                m_Key.SetValue("EnableServer", "true");
                m_Key.SetValue("ServerPort", port);
            }
            else
            {
                m_Key.SetValue("EnableServer", "false");
                m_Key.SetValue("ServerPort", port);
            }
        }


        internal void Write(string valuestring, bool value)
        {
            if (value == false)
                m_Key.SetValue(valuestring, "false");
            else
                m_Key.SetValue(valuestring, "true");
        }



        internal void MakeFileAssociation(string extension)
        {
            Factory fac = new Factory();
            fac.SetFileAssociation(extension);            
        }
        


        internal void RemoveFileAssociation(string extension)
        {
            Factory fac = new Factory();
            fac.RemoveFileAssociation(extension);
        }



    }
}
